#ifndef HJ212_H
#define HJ212_H

#include <QObject>
#include <QString>
#include <QByteArray>
#include <QMetaEnum>
#include <QDateTime>
#include "testmodel.h"
#include "devicelist.h"

class HJ212_DATA
{
public:

    QString QN;
    int ST;
    int CN;
    QString PW;
    QString MN;
    int Flag;
    QString PNUM;
    QString PNO;
    QString CP;
    HJ212_DATA() {}
//    HJ212_DATA(QString QN_,QString ST_,QString CN_,QString PW_,QString MN_,unsigned char Flag_,QString PNUM_,QString PNO_,QString CP_)
//    {
//        //赋值
//        QN=QN_;ST=ST_;CN=CN_;PW=PW_;MN=MN_;Flag=Flag_;PNUM=PNUM_;PNO=PNO_;CP=CP_;
//        //更新datastr

//    }
//    HJ212_DATA(QString dataStr)
//    {

//    }


    //请求编码QN,系统编码ST,命令编码CN,访问密码PW,设备标识MN,拆包及应答Flag,总包数PNUM,包号PNO,指令参数CP
//    QString getDataString()
//    {
//        QString data="";
//        if(0==(Flag&0x02))//无分包
//        {
//            //data.sprintf("QN=%s;ST=%s;CN=%s;PW=%s;MN=%s;Flag=%d;CP=&&%s&&",QN,ST,CN,PW,MN,Flag,CP);
//        }
//        else//有分包
//        {

//        }
//        return data;
//    }
};


class HJ212
{
public:

    //GetSend:上位机查询下位机与下位机应答或者下位机上传与上位机应答,Set:上位机设置下位机,Req:下位机向上位机请求
    enum CNenum{
        //初始化命令
        Timeout_ReSend=1000,
        //参数命令
        LowerComputerTime_GetSend=1011,
        LowerComputerTime_Set,
        LowerComputerTimeCal_Req,
        RealTimeDataInterval_GetSend=1061,
        RealTimeDataInterval_Set,
        MinuteDataInterval_GetSend,
        MinuteDataInterval_Set,
        //数据命令-实时数据
        PollutantRealTimeData_GetSend=2011,
        PollutantRealTimeData_Stop,
        //数据命令-设备状态
        DeviceStaus_GetSend=2021,
        DeviceStaus_Stop,
        //数据命令-日数据
        PollutantDayHistoryData_GetSend=2031,
        DeviceRunDayHistoryData_GetSend=2041,
        //数据命令-分钟数据
        PollutantMinuteHistoryData_GetSend=2051,
        //数据命令-小时数据
        PollutantHourHistoryData_GetSend=2061,
        //数据命令-其它数据
        DataCollectionDeviceRunTime_Send=2081,
        //控制命令
        ZeroRangeCalibration_Set=3011,
        InstantSampling_Set,
        CleaningBackblowing,
        ComparingSampling,
        ExceedingStandardSample_GetSend,
        SamplingTimePeriod_Set,
        SamplingTimePeriod_GetSend,
        SamplingTime_GetSend,
        DeviceId_GetSend,
        LowerComputerInfo_GetSend,
        LowerComputerInfo_Set,
        //交互命令
        RequestResponse=9011,
        ExecutionResults,
        NotificationResponse,
        DataResponse

    };
    enum STenum{
        SurfaceWaterQualityMonitor=21,//地表水质量监测
        AirQualityMonitor,//空气质量监测
        SoundEnvironmentQualityMonitor,//声环境质量监测
        GroundWaterQualityMonitor,//地下水质量监测
        SoilQualityMonitor,//土壤质量监测
        SeaWaterQualityMonitor,//海水质量监测
        VOCMonitor,//挥发性有机物监测
        AtmosphericPollutionSource=31,//大气环境污染源
        SurfaceWaterPollutionSource,//地表水体环境污染源
        GroundWaterPollutionSource,//地下水体环境污染源
        OceanPollutionSource,//海洋环境污染源
        SoilPollutionSource,//土壤环境污染源
        SoundPollutionSource,//声环境污染源
        VibrationPollutionSource,//振动环境污染源
        RadioactivePollutionSource,//放射性环境污染源
        RaiseDustPollutionSource,//工地扬尘污染源
        ElectromagneticPollutionSource=41,//电磁环境污染源
        FlueGasEmissionProcessMonitor=51,//烟气排放过程监控
        SewageDischargeProcessMonitor,//污水排放过程监控
        SystemInteraction=91//系统交互
    };

    HJ212();

    static bool recvCN1000(QString &qstrSrc,StationModel &object);
    static QString recvCN1011(QString &qstrSrc);
    static bool recvCN1012(QString &qstrSrc,Device &object);
    static QString recvCN1062(QString &qstrSrc);

    static QString GetCpValueByKey(QString &qstrSrc,QString key);

    static QString ResponseData(HJ212_DATA &object,QString cpStr,int Flag=4);
    static QString ReqReponse(HJ212_DATA &object,int QnRtn=1);
    static QString ReqResult(HJ212_DATA &object,int ExeRtn=1);

    static QString getDataPacket(QString msgtext);
    static int getDataObject(QString recvmsg,HJ212_DATA &object,StationModel &station);
    static QString getQN();
    static QString getDataTime();
    static unsigned int CRC16_Checkout (const QString Str, unsigned int usDataLen );
    static bool IsNumber(QString &qstrSrc);
    static bool IsHex(QString &qstrSrc);
};

#endif // HJ212_H
